package com.itheima.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@Slf4j
//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    @Override // 初始化方法, 只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        // System.out.println("初始化方法");
        log.info("初始化方法");
    }

    @Override // 拦截到请求之后调用, 调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //System.out.println("拦截方法");
        log.info("Demo: 拦截方法, 放行前");
        filterChain.doFilter(servletRequest, servletResponse);
        log.info("Demo: 拦截方法, 放行后");
    }

    @Override // 销毁方法, 只调用一次
    public void destroy() {
        //System.out.println("销毁方法");
        log.info("销毁方法");
    }
}
